package com.smartfactory.sail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smartfactory.sail.dto.ContractAmountDto;
import com.smartfactory.sail.entity.Contract;
import com.smartfactory.sail.mapper.ContractMapper;
import com.smartfactory.sail.service.IContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartfactory.sail.utils.PageUtils;
import com.smartfactory.sail.vo.PageParam;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同表 服务实现类
 * </p>
 *
 * @author 王巨壁
 * @since 2019-07-24
 */
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements IContractService {

    private ContractMapper contractMapper;

    public ContractServiceImpl(ContractMapper contractMapper) {
        this.contractMapper = contractMapper;
    }

    @Override
    public List<Map<String, Object>> listContract(Map<String,Object> queryParam, PageParam pageParam) {
        Page<Map<String,Object>> page = new Page<>();
        PageUtils.createPage(page, pageParam);
        QueryWrapper<Map<String,Object>> query = new QueryWrapper<>();
        query.allEq(queryParam);
        return contractMapper.getListPage(page, query);
    }

    @Override
    public ContractAmountDto getSignAmount() {
        ContractAmountDto contractAmountDto = new ContractAmountDto();
        Double monthAmount = contractMapper.getMonthAmount();
        Double halfYearAmount = contractMapper.getHalfYearAmount();
        Double yearAmount = contractMapper.getYearAmount();
        contractAmountDto.setMonthAmount(monthAmount);
        contractAmountDto.setHalfYearAmount(halfYearAmount);
        contractAmountDto.setYearAmount(yearAmount);
        return contractAmountDto;
    }
}
